/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Parallel;

import java.util.concurrent.ConcurrentHashMap;

/**
 *
 * @author zwirek
 */
public class CharArrPool {

//    static private ConcurrentHashMap<String, Object> pool;
    static private ConcurrentHashMap<String,char[]> map;

    public static char[] getCanonicalVersion(char[] str) {
//        if (pool == null) {
//            pool = new ConcurrentHashMap<char[], Object>();
//        }
//        for (char[] c : pool.keySet()) {
//            if(c.length!=str.length){
//                continue;
//            }
//            for (int i = 0; i < c.length; i++) {
//                if(c[i]!=str[i]){
//                    break;
//                }else{
//                    if(i==c.length-1){
//                        return c;
//                    }
//                }
//
//            }
//        }
//        pool.put(str, "");
//        return str;
//        //return pool.
//
    if(map==null){
        map = new ConcurrentHashMap<String,char[]>();
    }
    String s = new String(str);
    char[] canon = map.putIfAbsent(s, str);
    return (canon == null) ? str : canon;
    }
}
